class Solution {
public:
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        stack<int> st;
        int cur1 = 0, cur2 = 0;
        while (cur1 < pushed.size())
        {
            st.push(pushed[cur1++]);
            while (!st.empty() && st.top() == popped[cur2])
            {
                st.pop();
                cur2++;
            }
        }
        return st.empty();

    }
};